home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
ttedit
/
toolbar.bas
< prev
next >
Wrap
BASIC Source File
|
1994-11-28
|
15KB
|
442 lines
Option Explicit
Dim ButtonCount As Integer
Dim StatusText As String ' The statusbar caption
Dim Parents() As Form ' the parent form of each button
Dim Menus() As Menu 'array of menus each button is linked to
Const BUTTONS_DOWN = 100
Const BUTTONS_DISABLED = 200
Global Const RIGHT_JUSTIFY_BUTTONS = -2
Global Const SPACE_BETWEEN_BUTTONS = -1
' Flags for monitoring ToolTips
Dim TT_Control As Control
Dim TT_CurrentWindow As Integer
Dim TT_StartTime As Long
Dim TT_Visible As Integer
Dim TT_Point As PointAPI
Dim TT_LastDisplayed As Long
Function BaseButton (Index As Integer) As Integer
BaseButton = Index
If Index >= BUTTONS_DISABLED Then
BaseButton = Index - BUTTONS_DISABLED
ElseIf Index >= BUTTONS_DOWN Then
BaseButton = Index - BUTTONS_DOWN
End If
End Function
'
' This loop generates the Disabled and Down images ready for use.
'
Sub Create_OtherButtons (ButtonParent As Form, PicBox As PictureBox, BC As Integer, Start As Integer, Finish As Integer)
ButtonCount = BC
ReDim Preserve Parents(ButtonCount)
ReDim Preserve Menus(ButtonCount)
Dim X As Integer
For X = Start To Finish
PicBox.Picture = ButtonParent.ToolButton(X).Picture
PushDown PicBox
Load ButtonParent.ToolButton(BUTTONS_DOWN + X)
ButtonParent.ToolButton(BUTTONS_DOWN + X).Left = ButtonParent.ToolButton(X).Left
ButtonParent.ToolButton(BUTTONS_DOWN + X).Top = ButtonParent.ToolButton(X).Top
ButtonParent.ToolButton(BUTTONS_DOWN + X).Tag = ButtonParent.ToolButton(X).Tag
ButtonParent.ToolButton(BUTTONS_DOWN + X).Picture = PicBox.Image
PicBox.Picture = ButtonParent.ToolButton(X).Picture
PicBox.Cls
DisableButton PicBox
Load ButtonParent.ToolButton(BUTTONS_DISABLED + X)
ButtonParent.ToolButton(BUTTONS_DISABLED + X).Left = ButtonParent.ToolButton(X).Left
ButtonParent.ToolButton(BUTTONS_DISABLED + X).Top = ButtonParent.ToolButton(X).Top
ButtonParent.ToolButton(BUTTONS_DISABLED + X).Tag = ButtonParent.ToolButton(X).Tag
ButtonParent.ToolButton(BUTTONS_DISABLED + X).Picture = PicBox.Image
Set Parents(X) = ButtonParent
Next
End Sub
'
' This actually creates the Disabled image from the Up image.
' We need a picture box for this to work
'
Private Sub DisableButton (Button As PictureBox)
Dim SX1 As Integer
Dim SX2 As Integer
Dim SY1 As Integer
Dim SY2 As Integer
Dim DX As Integer
Dim DY As Integer
Dim R As Integer
Dim LR As Long
Dim rgbFace As Long
Dim rgbShadow As Long
Dim rgbHilight As Long
Dim rgbFrame As Long
Dim Dest_hDC As Integer
Dim hdcMono As Integer
Dim hbmMono As Integer
Dim hbmTemp As Integer
Dim hbmDefault As Integer
Dim hdcTemp As Integer
Dim hbr As Integer
Dim hbrOld As Integer
SX1 = 1
SY1 = 1
SX2 = Button.ScaleWidth - 3
SY2 = Button.ScaleHeight - 3
DX = 1
DY = 1
Dest_hDC = Button.hDC
rgbFace = GetSysColor(COLOR_BTNFACE)
rgbShadow = GetSysColor(COLOR_BTNSHADOW)
rgbHilight = GetSysColor(COLOR_BTNHIGHLIGHT)
rgbFrame = GetSysColor(COLOR_WINDOWFRAME)
hdcTemp = CreateCompatibleDC(Dest_hDC)
hbmTemp = CreateCompatibleBitmap(Dest_hDC, SX2 - SX1 + 1, SY2 - SY1 + 1)
hdcMono = CreateCompatibleDC(Dest_hDC)
hbmMono = CreateBitmap(SX2 - SX1 + 1, SY2 - SY1 + 1, 1, 1, ByVal 0&)
R = SelectObject(hdcMono, hbmMono)
R = SelectObject(hdcTemp, hbmTemp)
R = BitBlt(hdcTemp, DX, DY, SX2 - SX1 + 1, SY2 - SY1 + 1, Dest_hDC, SX1, SY1, SRCCOPY)
R = PatBlt(hdcMono, DX, DY, SX2 - SX1 + 1, SY2 - SY1 + 1, WHITENESS)
LR = SetBkColor(hdcTemp, rgbFace) ' // 1's in mono -> 1
R = BitBlt(hdcMono, DX, DY, SX2 - SX1 + 1, SY2 - SY1 + 1, hdcTemp, SX1, SY1, SRCCOPY)
LR = SetBkColor(hdcTemp, rgbHilight) ' // 1's in mono -> 1
R = BitBlt(hdcMono, DX, DY, SX2 - SX1 + 1, SY2 - SY1 + 1, hdcTemp, SX1, SY1, SRCPAINT)
LR = SetTextColor(Dest_hDC, &H0) ' // 0's in mono -> 0 (for ROP)
LR = SetBkColor(Dest_hDC, &HFFFFFF) ' // 1's in mono -> 1
hbr = CreateSolidBrush(rgbHilight)
hbrOld = SelectObject(Dest_hDC, hbr)
R = BitBlt(Dest_hDC, DX + 1, DY + 1, SX2 - SX1 + 1, SY2 - SY1 + 1, hdcMono, SX1, SY1, &HB8074A)
R = SelectObject(Dest_hDC, hbrOld)
R = DeleteObject(hbr)
' // Gray out picture
hbr = CreateSolidBrush(rgbShadow)
hbrOld = SelectObject(Dest_hDC, hbr)
' // Draw the shadow color where we have 0's in the mask.
R = BitBlt(Dest_hDC, DX, DY, SX2 - SX1 + 1, SY2 - SY1 + 1, hdcMono, SX1, SY1, &HB8074A)
R = SelectObject(Dest_hDC, hbrOld)
R = DeleteObject(hbr)
R = DeleteDC(hdcMono)
R = DeleteDC(hdcTemp)
R = DeleteObject(hbmMono)
R = DeleteObject(hbmTemp)
Button.Refresh
End Sub
Private Sub DisplayHelp (Help$)
If Len(Help$) Then ' Double check help$
' Make sure help form is invisible:
frmToolTip.Hide
' Change caption of label:
frmToolTip.Label1.Caption = Help$
' Offset the form from the cursor
frmToolTip.Top = (TT_Point.Y + TT_Control.Height + 10) * Screen.TwipsPerPixelY
frmToolTip.Left = TT_Point.X * Screen.TwipsPerPixelX
frmToolTip.Width = (frmToolTip.Label1.Width + 6) * Screen.TwipsPerPixelX
frmToolTip.Height = (frmToolTip.Label1.Height + 2) * Screen.TwipsPerPixelY
If Screen.Width < frmToolTip.Width + frmToolTip.Left Then frmToolTip.Left = Screen.Width - 1.1 * frmToolTip.Width
' Make sure form is on top:
frmToolTip.ZOrder
' Show form without the focus:
If ShowWindow(frmToolTip.hWnd, SW_SHOWNOACTIVATE) Then
End If
TT_Visible = True
Else
' Hide the form:
frmToolTip.Hide
TT_Visible = False
End If
End Sub
Private Sub EnableButton (Button As PictureBox)
Button.Cls
Button.Refresh
Button.Enabled = True
End Sub
Function GetButtonState (Index As Integer)
GetButtonState = Menus(Index).Checked
End Function
'
' This calculates the number we need to use in the Sendmessage to
' Click the linked menu
'
Function GetMenuIndex (mnu As Menu) As Integer
Dim X As Integer, Index As Integer
Dim F As Form
Set F = mnu.Parent
For X = 0 To F.Controls.Count - 1
If TypeOf F.Controls(X) Is Menu Then Exit For
Next
Do While Not F.Controls(X + Index) Is mnu
Index = Index + 1
Loop
GetMenuIndex = Index + 1
End Function
Function GetMenuTag (Index As Integer) As String
If Not Menus(Index) Is Nothing Then GetMenuTag = Menus(Index).Tag
End Function
Sub LinkMenu (ButtonID As Integer, mnu As Menu)
Set Menus(ButtonID) = mnu
End Sub
Sub PositionButtons (Positions() As Integer, ToolBar As Control)
' We need to position the buttons because the position of buttons cannot be
' guaranteed when run on machines with Large screen fonts if designed in small fonts mode.
Dim X As Integer
Dim Direction As Integer
Dim Next_Left As Integer
Dim LastToolButton
For X = 0 To UBound(Positions)
Select Case Positions(X)
Case RIGHT_JUSTIFY_BUTTONS
Direction = RIGHT_JUSTIFY_BUTTONS
Next_Left = ToolBar.ScaleWidth - ToolBar.Parent.ToolButton(LastToolButton).Width
Case SPACE_BETWEEN_BUTTONS
If Direction <> RIGHT_JUSTIFY_BUTTONS Then
Next_Left = Next_Left + ToolBar.Parent.ToolButton(0).Width / 3
Else
Next_Left = Next_Left - ToolBar.Parent.ToolButton(0).Width / 3
End If
Case Else
LastToolButton = Positions(X)
ToolBar.Parent.ToolButton(Positions(X)).Left = Next_Left
ToolBar.Parent.ToolButton(Positions(X) + BUTTONS_DOWN).Left = Next_Left
ToolBar.Parent.ToolButton(Positions(X) + BUTTONS_DISABLED).Left = Next_Left
If Direction <> RIGHT_JUSTIFY_BUTTONS Then
Next_Left = Next_Left + ToolBar.Parent.ToolButton(Positions(X)).Width
Else
Next_Left = Next_Left - ToolBar.Parent.ToolButton(Positions(X)).Width
End If
End Select
Next
End Sub
Private Sub PushDown (PicBox As PictureBox)
Dim X As Integer
Dim mWidth As Integer
Dim mHeight As Integer
PicBox.Cls
mHeight = PicBox.ScaleHeight
mWidth = PicBox.ScaleWidth
' The next 3 lines chang